package com.zf.museum.repository;

import com.zf.museum.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Repository
public interface UserRepository extends JpaRepository<User, Long>{

    @Transactional//必须添加
    @Modifying//必须添加
    @Query("update User u set u.name= :name where u.openId= :openId")
    void updateName(@Param("name") String name, @Param("openId") String openId);

    Set<User> getTop10ByOrderByRankAsc();

    Set<User> getAllByOrderByScoreDesc();

    User getUserByOpenId(String openId);

}
